/*
 * ProgramInfo.java
 *
 * Created on June 12, 2005, 3:43 PM
 */

package ika.gui;

import edu.stanford.ejalbert.BrowserLauncher;
import edu.stanford.ejalbert.exception.BrowserLaunchingInitializingException;
import edu.stanford.ejalbert.exception.UnsupportedOperatingSystemException;
import ika.mapanalyst.ApplicationInfo;

/**
 *
 * @author  Bernhard Jenny, Institute of Cartography, ETH Zurich.
 */
public class ProgramInfo extends javax.swing.JFrame {
    
    private static ProgramInfo info = null;
    
    /** Creates new form ProgramInfo */
    private ProgramInfo() {

        initComponents();
        
        // window title
        String windowTitle;
        if (com.muchsoft.util.Sys.isMacOSX())
            windowTitle = "";
        else
            windowTitle = "Info";
        this.setTitle(windowTitle);
        
        // name and version
        this.nameLabel.setText(ApplicationInfo.getApplicationName());
        this.versionLabel.setText(ApplicationInfo.getApplicationVersion());
        
        // copyright
        this.copyrightLabel.setText(ApplicationInfo.getCopyright());
        
        // homepage
        this.homepageButton.setText(ApplicationInfo.getHomepage());
        
        // operating system
        String osString = "Operating System: " + System.getProperty("os.name")
        + " " + System.getProperty("os.version");
        this.osInfoLabel.setText(osString);

        // java vm version
        String javaString = "Java VM " + System.getProperty("java.version");
        javaString += " (" + System.getProperty("sun.arch.data.model") + " bit)";
        javaString += " by ";
        javaString += System.getProperty("java.vendor");       
        this.javaInfoLabel.setText(javaString);
        
        this.pack();

        // location
        java.awt.Dimension screen = this.getToolkit().getScreenSize();
        java.awt.Dimension dialog = this.getSize();
        this.setLocation( (screen.width - dialog.width) / 2,
                (screen.height - dialog.height) / 2 );
        this.setVisible(true);
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        nameLabel = new javax.swing.JLabel();
        copyrightLabel = new javax.swing.JLabel();
        infoLabel = new javax.swing.JLabel();
        iconLabel = new javax.swing.JLabel();
        versionLabel = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        osInfoLabel = new javax.swing.JLabel();
        javaInfoLabel = new javax.swing.JLabel();
        homepageButton = new javax.swing.JButton();

        setTitle("About");
        setFont(new java.awt.Font("#GungSeo", 0, 10));
        setName("infoFrame"); // NOI18N
        setResizable(false);
        getContentPane().setLayout(new java.awt.GridBagLayout());

        nameLabel.setFont(new java.awt.Font("Lucida Grande", 1, 14)); // NOI18N
        nameLabel.setText("Name");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.insets = new java.awt.Insets(20, 20, 15, 20);
        getContentPane().add(nameLabel, gridBagConstraints);

        copyrightLabel.setFont(new java.awt.Font("Lucida Grande", 0, 11)); // NOI18N
        copyrightLabel.setText("Copyright");
        copyrightLabel.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 25, 1, 25));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.insets = new java.awt.Insets(15, 25, 15, 25);
        getContentPane().add(copyrightLabel, gridBagConstraints);

        infoLabel.setFont(new java.awt.Font("Lucida Grande", 0, 11)); // NOI18N
        infoLabel.setText("For more information:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.insets = new java.awt.Insets(0, 14, 0, 14);
        getContentPane().add(infoLabel, gridBagConstraints);

        iconLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ika/icons/logo128x128.gif"))); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.insets = new java.awt.Insets(25, 0, 0, 0);
        getContentPane().add(iconLabel, gridBagConstraints);

        versionLabel.setFont(new java.awt.Font("Lucida Grande", 0, 11)); // NOI18N
        versionLabel.setText("Version");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.insets = new java.awt.Insets(0, 20, 0, 20);
        getContentPane().add(versionLabel, gridBagConstraints);

        jSeparator1.setPreferredSize(new java.awt.Dimension(200, 10));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 6;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        getContentPane().add(jSeparator1, gridBagConstraints);

        osInfoLabel.setFont(new java.awt.Font("Lucida Grande", 0, 11)); // NOI18N
        osInfoLabel.setText("Operating System");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 7;
        gridBagConstraints.insets = new java.awt.Insets(14, 0, 0, 0);
        getContentPane().add(osInfoLabel, gridBagConstraints);

        javaInfoLabel.setFont(new java.awt.Font("Lucida Grande", 0, 11)); // NOI18N
        javaInfoLabel.setText("Java Version");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 8;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 20, 0);
        getContentPane().add(javaInfoLabel, gridBagConstraints);

        homepageButton.setFont(new java.awt.Font("Lucida Grande", 0, 11)); // NOI18N
        homepageButton.setForeground(new java.awt.Color(0, 70, 160));
        homepageButton.setText("homepage");
        homepageButton.setBorderPainted(false);
        homepageButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                homepageButtonActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.insets = new java.awt.Insets(0, 14, 20, 14);
        getContentPane().add(homepageButton, gridBagConstraints);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void homepageButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_homepageButtonActionPerformed
        try {
            new BrowserLauncher().openURLinBrowser(homepageButton.getText());
        } catch (BrowserLaunchingInitializingException ex) {
            //Logger.getLogger(ProgramInfo.class.getName()).log(Level.SEVERE, null, ex);
        } catch (UnsupportedOperatingSystemException ex) {
            //Logger.getLogger(ProgramInfo.class.getName()).log(Level.SEVERE, null, ex);
        }
}//GEN-LAST:event_homepageButtonActionPerformed
        
    public static void showInfo() {
        if (info == null){
            info = new ProgramInfo();
        }else{
            info.setExtendedState( java.awt.Frame.NORMAL );
            info.setVisible(true);
        }
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ProgramInfo().setVisible(true);
            }
        });
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel copyrightLabel;
    private javax.swing.JButton homepageButton;
    private javax.swing.JLabel iconLabel;
    private javax.swing.JLabel infoLabel;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JLabel javaInfoLabel;
    private javax.swing.JLabel nameLabel;
    private javax.swing.JLabel osInfoLabel;
    private javax.swing.JLabel versionLabel;
    // End of variables declaration//GEN-END:variables
    
}
